package com.lin.lostandfound.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lin.lostandfound.mapper.MenuItemMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.lin.lostandfound.bean.MenuItem;
import com.lin.lostandfound.service.IMenuItemService;

@Service("menuItemService")
public class MenuItemService implements IMenuItemService {

	@Autowired
	private MenuItemMapper mapper;

	@Override
	public boolean add(MenuItem menuItem) {
		
		return mapper.insert(menuItem) != -1;
	}

	@Override
	public boolean modifyStatus(Long id, int status) {

		MenuItem item = new MenuItem();
		item.setId(id);
		item.setStatus(status);
		return mapper.updateById(item)!=-1;
	}
	
	// 修改权限
	@Override
	public boolean modifyAuthority(Long id, int authority) {
		MenuItem item = new MenuItem();
		item.setId(id);
		item.setAuthority(authority);
		return mapper.updateById(item)!=-1;
	}

	@Override
	public boolean remove(Long id) {
		// TODO Auto-generated method stub
		return false;
	}

	// 根据主键id查询
	@Override
	public MenuItem queryById(Long id) {
		QueryWrapper<MenuItem> wrapper = new QueryWrapper<>();
		wrapper.eq("id",id);
		wrapper.eq("status",1);
		wrapper.orderByAsc("sort");

		return mapper.selectOne(wrapper);
	}
	
	// 根据菜单id查询
	@Override
	public MenuItem queryByMenuId(String menuId) {
		QueryWrapper<MenuItem> wrapper = new QueryWrapper<>();
		wrapper.eq("menuId",menuId);
		wrapper.eq("status",1);
		wrapper.orderByAsc("sort");

		return mapper.selectOne(wrapper);
	}
	
	// 根据父菜单id查询
	@Override
	public List<MenuItem> queryAllByParentId(String parentId) {
		QueryWrapper<MenuItem> wrapper = new QueryWrapper<>();
		wrapper.eq("parentId",parentId);
		wrapper.eq("status",1);
		wrapper.orderByAsc("sort");

		return mapper.selectList(wrapper);
	}
	
	@Override
	public List<MenuItem> queryAll() {

		QueryWrapper<MenuItem> wrapper = new QueryWrapper<>();

		wrapper.orderByAsc("sort");

		return mapper.selectList(wrapper);
	}
	
	@Override
	public List<MenuItem> queryAll(int authority) {

		QueryWrapper<MenuItem> wrapper = new QueryWrapper<>();
		wrapper.eq("authority",authority);
		wrapper.eq("status",1);
		wrapper.orderByAsc("sort");

		return mapper.selectList(wrapper);
	}

}
